/*
 * FormMahasiswa.java
 *
 * Created on June 23, 2007, 3:59 AM
 */

package latihanibatis.ui;

import com.ibatis.common.resources.Resources;
import com.ibatis.dao.client.DaoManager;
import com.ibatis.dao.client.DaoManagerBuilder;
import java.io.IOException;
import java.io.Reader;
import javax.swing.JFormattedTextField;
import latihanibatis.dao.MahasiswaDao;
import latihanibatis.domain.Mahasiswa;
import latihanibatis.ui.event.BtnCekNim;
import latihanibatis.ui.event.BtnDelete;
import latihanibatis.ui.event.BtnSimpan;
import latihanibatis.ui.event.BtnCari;
import latihanibatis.ui.event.BtnEdit;
import latihanibatis.ui.event.BtnUpdate;

/**
 *
 * @author  javamaniac
 */
public class FormMahasiswa extends javax.swing.JFrame {
    
    private MhsTabelModel tabelModel;
    private MahasiswaDao mhsDao;

    /** Creates new form FormMahasiswa */
    public FormMahasiswa(MhsTabelModel tabelModel, MahasiswaDao dao) {
        this.tabelModel = tabelModel;;
        this.mhsDao = dao;
        
        initComponents();
        initListener();
        initComponentFocus();
        
        setLocationRelativeTo(null);
    }
    
    private void initComponentFocus() {
        txtAlamat.addFocusListener(new ComponentFocus(txtAlamat));
        txtKeterangan.addFocusListener(new ComponentFocus(txtKeterangan));
        txtKota.addFocusListener(new ComponentFocus(txtKota));
        txtNIM.addFocusListener(new ComponentFocus(txtNIM));
        txtNama.addFocusListener(new ComponentFocus(txtNama));
    }
    
    private void initListener() {
        btnCekNim.addActionListener(new BtnCekNim(panelStatus1, txtNIM, this, mhsDao));
        
        btnCari.addActionListener(new BtnCari(lblNIM, txtNIM, lblNama, txtNama,
            lblKota, txtKota,  lblAlamat, txtAlamat, lblKeterangan, txtKeterangan,
            btnCekNim, btnCari, btnSimpan, panelStatus1, tabelModel, mhsDao));
        
        btnUpdate.addActionListener(new BtnUpdate(txtNIM, txtNama, txtKota,
            txtAlamat, txtKeterangan, panelStatus1, jTable1, tabelModel, btnCari,
            btnUpdate, btnSimpan, btnEdit, btnDelete, mhsDao));
        
        btnSimpan.addActionListener(new BtnSimpan(txtNIM, txtNama, txtKota,
            txtAlamat, txtKeterangan, panelStatus1, tabelModel, btnCari, btnSimpan,
            btnEdit, btnDelete, mhsDao));
        
        btnEdit.addActionListener(new BtnEdit(txtNIM, txtNama, txtKota, txtAlamat,
            txtKeterangan, tabelModel, jTable1, panelStatus1, btnCari, btnUpdate,
            btnSimpan, btnEdit, btnDelete));
        
        btnDelete.addActionListener(new BtnDelete(tabelModel, panelStatus1, 
            jTable1, mhsDao));
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        DataMahasiswa = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jTable1.getTableHeader().setReorderingAllowed(false);
        jTable1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);

        /* End Table Configuration */
        btnEdit = new javax.swing.JButton();
        btnDelete = new javax.swing.JButton();
        btnRefresh = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        lblNIM = new javax.swing.JLabel();
        lblNama = new javax.swing.JLabel();
        txtNama = new javax.swing.JTextField();
        lblAlamat = new javax.swing.JLabel();
        lblKota = new javax.swing.JLabel();
        lblKeterangan = new javax.swing.JLabel();
        txtAlamat = new javax.swing.JTextField();
        txtKota = new javax.swing.JTextField();
        txtKeterangan = new javax.swing.JTextField();
        btnCari = new javax.swing.JButton();
        btnUpdate = new javax.swing.JButton();
        btnCekNim = new javax.swing.JButton();
        btnSimpan = new javax.swing.JButton();
        txtNIM = new JFormattedTextField();
        panelStatus1 = new latihanibatis.ui.PanelStatus();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Project Latihan Ibatis");
        setAlwaysOnTop(true);
        setResizable(false);
        DataMahasiswa.setBorder(javax.swing.BorderFactory.createTitledBorder("Data Mahasiswa"));
        jTable1.setModel(tabelModel);
        jScrollPane1.setViewportView(jTable1);

        btnEdit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/latihanibatis/images/edit.gif")));
        btnEdit.setToolTipText("Edit Data Mahasiswa");
        btnEdit.setIconTextGap(2);

        btnDelete.setIcon(new javax.swing.ImageIcon(getClass().getResource("/latihanibatis/images/delete.gif")));
        btnDelete.setToolTipText("Hapus Data Mahasiswa");
        btnDelete.setIconTextGap(2);

        btnRefresh.setIcon(new javax.swing.ImageIcon(getClass().getResource("/latihanibatis/images/refresh.png")));
        btnRefresh.setToolTipText("Refresh Table Mahasiswa");
        btnRefresh.setIconTextGap(2);

        javax.swing.GroupLayout DataMahasiswaLayout = new javax.swing.GroupLayout(DataMahasiswa);
        DataMahasiswa.setLayout(DataMahasiswaLayout);
        DataMahasiswaLayout.setHorizontalGroup(
            DataMahasiswaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, DataMahasiswaLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 536, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(DataMahasiswaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(DataMahasiswaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(btnDelete, 0, 0, Short.MAX_VALUE)
                        .addComponent(btnEdit, javax.swing.GroupLayout.PREFERRED_SIZE, 33, Short.MAX_VALUE))
                    .addComponent(btnRefresh))
                .addContainerGap())
        );

        DataMahasiswaLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btnDelete, btnEdit, btnRefresh});

        DataMahasiswaLayout.setVerticalGroup(
            DataMahasiswaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(DataMahasiswaLayout.createSequentialGroup()
                .addGroup(DataMahasiswaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(DataMahasiswaLayout.createSequentialGroup()
                        .addComponent(btnEdit)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnDelete)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 58, Short.MAX_VALUE)
                        .addComponent(btnRefresh))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 142, Short.MAX_VALUE))
                .addContainerGap())
        );

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));
        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/latihanibatis/images/Mahasiswa.png")));

        jLabel2.setFont(new java.awt.Font("Dialog", 1, 18));
        jLabel2.setText("Menu Mahasiswa");

        jLabel3.setFont(new java.awt.Font("Dialog", 0, 12));
        jLabel3.setText("Silahkan Tambah, Edit, Hapus dan Cari Data Mahasiswa");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addComponent(jLabel3)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 242, Short.MAX_VALUE)
                .addComponent(jLabel1)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel3))
                    .addComponent(jLabel1))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        lblNIM.setText("NIM * :");

        lblNama.setText("Nama * :");

        lblAlamat.setText("Alamat * :");

        lblKota.setText("Kota Asal * :");

        lblKeterangan.setText("Keterangan :");

        btnCari.setText("Cari");
        btnCari.setToolTipText("Cari Data Mahasiswa");

        btnUpdate.setText("Update");
        btnUpdate.setToolTipText("Update Data Mahasiswa");
        btnUpdate.setEnabled(false);

        btnCekNim.setText("Cek");

        btnSimpan.setText("Simpan");
        btnSimpan.setToolTipText("Simpan Data Mahasiswa");

        txtNIM.setValue(0);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblKeterangan, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lblAlamat, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lblNIM, javax.swing.GroupLayout.Alignment.TRAILING))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(txtAlamat, javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addComponent(txtNIM, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnCekNim)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(lblKota)
                            .addComponent(lblNama))
                        .addGap(4, 4, 4)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtKota, javax.swing.GroupLayout.DEFAULT_SIZE, 145, Short.MAX_VALUE)
                            .addComponent(txtNama, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btnUpdate)
                            .addComponent(btnCari)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(txtKeterangan, javax.swing.GroupLayout.DEFAULT_SIZE, 440, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnSimpan)))
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(DataMahasiswa, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(panelStatus1, javax.swing.GroupLayout.DEFAULT_SIZE, 650, Short.MAX_VALUE)
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btnCari, btnSimpan, btnUpdate});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(17, 17, 17)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblNIM)
                    .addComponent(btnCari)
                    .addComponent(btnCekNim)
                    .addComponent(txtNama, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblNama)
                    .addComponent(txtNIM, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(btnUpdate)
                        .addComponent(txtKota, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(lblAlamat)
                        .addComponent(txtAlamat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(lblKota)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblKeterangan)
                    .addComponent(txtKeterangan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnSimpan))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(DataMahasiswa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 12, Short.MAX_VALUE)
                .addComponent(panelStatus1, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel DataMahasiswa;
    private javax.swing.JButton btnCari;
    private javax.swing.JButton btnCekNim;
    private javax.swing.JButton btnDelete;
    private javax.swing.JButton btnEdit;
    private javax.swing.JButton btnRefresh;
    private javax.swing.JButton btnSimpan;
    private javax.swing.JButton btnUpdate;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JLabel lblAlamat;
    private javax.swing.JLabel lblKeterangan;
    private javax.swing.JLabel lblKota;
    private javax.swing.JLabel lblNIM;
    private javax.swing.JLabel lblNama;
    private latihanibatis.ui.PanelStatus panelStatus1;
    private javax.swing.JTextField txtAlamat;
    private javax.swing.JTextField txtKeterangan;
    private javax.swing.JTextField txtKota;
    private javax.swing.JFormattedTextField txtNIM;
    private javax.swing.JTextField txtNama;
    // End of variables declaration//GEN-END:variables
    
}
